package com.project.common.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import com.project.common.core.domain.R;
import com.project.common.core.domain.TableDataInfo;

import java.util.List;

public class BaseController {

    public R<Void> toR(int rows){
        return rows > 0 ? R.ok() : R.fail();
    }

    public R<Void> toR(boolean result){
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list){
        if(CollectionUtil.isEmpty(list)){
            return TableDataInfo.empty();
        }
        //分页插件提供的方法 查询总数
        return TableDataInfo.success(list, Math.toIntExact(new PageInfo<>(list).getTotal()));
    }
}
